package demo.http.filter;

import net.jueb.sniff4j.extr.base.AbstractRuntime;
import net.jueb.sniff4j.extr.build.channel.BlockChannel;
import net.jueb.sniff4j.extr.build.channel.RBuildChannel;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.DefaultHttpResponse;
import io.netty.util.CharsetUtil;

public class HttpResponseFilter extends HttpObjectFilter {
	
	public HttpResponseFilter(Channel fromChannel, Channel toChannel,
			AbstractRuntime runtime) {
		super(fromChannel, toChannel, runtime);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected BlockChannel<?, ?> getBlockChannel(Object filtTarget) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected RBuildChannel<?> getRBuildChannel(Object filtTarget) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void showFiltTargetInfo(Object filtTarget) {
		Object object=filtTarget;
		//DefaultFullHttpRequest是DefaultHttpRequest的子类
		if(object instanceof DefaultFullHttpResponse)
		{
			DefaultFullHttpResponse dfr=(DefaultFullHttpResponse)object;
			log.info(info+getHeadersString(dfr.headers())+"Content:\n"+new String(getContent(dfr),CharsetUtil.UTF_8));
		}else if(object instanceof DefaultHttpResponse)
		{
			DefaultHttpResponse dr=(DefaultHttpResponse)object;
			log.info(info+getHeadersString(dr.headers()));
		}else
		{
			log.info(info+object.toString());
		}
	}
}
